<!DOCTYPE html>
<!--
这是一个入门模板页面。通过此页面从头开发新的项目。
该页面删除了所有链接，仅提供所需的标签。
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="x-ua-compatible" content="ie=edge">

  <title>SuperScope | 个人信息</title>

  <!-- Font Awesome 图标 -->
  <link rel="stylesheet" href="../../static/plugins/fontawesome-free/css/all.min.css">
  <!-- 主题样式 -->
  <link rel="stylesheet" href="../../static/dist/css/adminlte.min.css">
  <!-- 离线 Google 字体: Source Sans Pro -->
  <link href="../../static/dist/css/google.css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
    <link rel="stylesheet" href="../../static/plugins/toastr/toastr.min.css">
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">

  <!-- 导航栏 -->
  <nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <!-- 左侧导航栏链接 -->
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
      </li>
      <li class="nav-item d-none d-sm-inline-block">
        <a href="{{ url_for('monitorMain') }}" class="nav-link">主页</a>
      </li>
    </ul>

    <!-- 搜索表单 -->
    <form class="form-inline ml-3">
      <div class="input-group input-group-sm">
        <input class="form-control form-control-navbar" type="search" placeholder="搜索" aria-label="Search">
        <div class="input-group-append">
          <button class="btn btn-navbar" type="submit">
            <i class="fas fa-search"></i>
          </button>
        </div>
      </div>
    </form>

    <!-- 右侧导航栏链接 -->
    <ul class="navbar-nav ml-auto">
      <li class="nav-item dropdown">
        <a class="nav-link" data-toggle="dropdown" href="#">
          <i class="far fa-bell"></i>
          <span class="badge badge-warning navbar-badge">15</span>
        </a>
        <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
          <span class="dropdown-header">15 条通知</span>
          <div class="dropdown-divider"></div>
<a href="{{ url_for('chat') }}" class="dropdown-item">
            <i class="fas fa-envelope mr-2"></i> 4 条新消息
            <span class="float-right text-muted text-sm">3 分钟前</span>
          </a>
          <div class="dropdown-divider"></div>
          <a href="#" class="dropdown-item">
            <i class="fas fa-users mr-2"></i> 8 个好友请求
            <span class="float-right text-muted text-sm">12 小时前</span>
          </a>
          <div class="dropdown-divider"></div>
          <a href="#" class="dropdown-item">
            <i class="fas fa-file mr-2"></i> 3 个新报告
            <span class="float-right text-muted text-sm">2 天前</span>
          </a>
          <div class="dropdown-divider"></div>
          <a href="#" class="dropdown-item dropdown-footer">查看所有通知</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#" role="button"><i
            class="fas fa-th-large"></i></a>
      </li>
    </ul>
  </nav>
  <!-- /.navbar -->

  <!-- 主侧边栏容器 -->
  <aside class="main-sidebar sidebar-dark-primary elevation-4">
    <!-- 品牌 Logo -->
    <a href="index3.html" class="brand-link">
      <img src="../../static/dist/img/periscope.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3"
           style="opacity: .8">
      <span class="brand-text font-weight-light">SuperScope</span>
    </a>

    <!-- Sidebar -->
    <div class="sidebar">
      <!-- 侧边栏用户面板（可选） -->
      <div class="user-panel mt-3 pb-3 mb-3 d-flex">
        <div class="info">
          <a href="#" id="HelloUser" class="d-block">Alexander Pierce</a>
        </div>
      </div>

      <!-- 侧边栏菜单 -->
      <nav class="mt-2">
        <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
          <!-- 使用 .nav-icon 类添加图标，
               或使用 font-awesome 或其他任何图标字体库 -->
            <li class="nav-item">
            <a href="{{ url_for('monitorMain') }}" class="nav-link">
              <i class="nav-icon fas fa-th"></i>
              <p>
                首页
              </p>
            </a>
          </li>
            <li class="nav-item has-treeview">
            <a href="#" class="nav-link">
              <i class="nav-icon fas fa-tachometer-alt"></i>
              <p>
                监控
                <i class="right fas fa-angle-left"></i>
              </p>
            </a>
            <ul class="nav nav-treeview">
                <li class="nav-item">
                <a href="{{ url_for('infraRed') }}" class="nav-link">
                  <i class="far fa-circle nav-icon"></i>
                  <p>红外监控</p>
                </a>
              </li>
                <li class="nav-item">
                <a href="{{ url_for('temperatureAndHumidity') }}" class="nav-link">
                  <i class="far fa-circle nav-icon"></i>
                  <p>温湿度监控</p>
                </a>
              </li>
                <li class="nav-item">
                <a href="{{ url_for('door') }}" class="nav-link">
                  <i class="far fa-circle nav-icon"></i>
                  <p>门监控</p>
                </a>
              </li>
            </ul>
          </li>
            <li class="nav-item">
            <a href="{{ url_for('sleepCheck') }}" class="nav-link">
              <i class="nav-icon fas fa-edit"></i>
              <p>
                查寝
              </p>
            </a>
          </li>
            <li class="nav-item">
            <a href="{{ url_for('personalInformation') }}" class="nav-link active">
              <i class="nav-icon fas fa-file"></i>
              <p>
                个人信息
              </p>
            </a>
          </li>
            <li id="adminMaintenance" class="nav-item">
            <a href="{{ url_for('adminMaintenance') }}" class="nav-link">
              <i class="nav-icon fas fa-plus-square"></i>
              <p>
                管理员维护
              </p>
            </a>
          </li>
        </ul>
      </nav>
      <!-- /.sidebar-menu -->
    </div>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. 包含页面内容 -->
  <div class="content-wrapper">
    <!-- 内容标题（页面标题） -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">个人信息</h1>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- 主体内容 -->
    <div class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-3">

            <!-- Profile Image -->
            <div class="card card-primary card-outline">
              <div class="card-body box-profile">
                <div class="text-center">
                  <img id="profileimg" class="profile-user-img img-fluid img-circle"
                       src=""
                       alt="User profile picture">
                </div>

                <h3 class="profile-username text-center" id="username"></h3>

                <p class="text-muted text-center" id="isadmin"></p>

                <ul class="list-group list-group-unbordered mb-3">
                  <li class="list-group-item">
                    <b>学号</b> <a class="float-right" id="userid"></a>
                  </li>
                  <li class="list-group-item">
                    <b>寝室号</b> <a class="float-right" id="dormitory"></a>
                  </li>
                  <li class="list-group-item">
                    <b>电话</b> <a class="float-right" id="phone"></a>
                  </li>
                </ul>

                <a class="btn btn-primary btn-block" href={{ url_for('login') }}><b>登出</b></a>

                  <button type="button" class="btn btn-danger btn-flat btn-block" data-toggle="modal" data-target="#modal-danger">
                  <b>注销</b>
                </button>

              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->

          </div>
          <!-- /.col -->

          <div class="col-md-6">
            <!-- jquery validation -->
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">修改 <small>个人信息</small></h3>
              </div>
              <!-- /.card-header -->
                <div class="card-body">
                  <div class="form-group">
                    <label for="changeDormitory">宿舍号</label>
                    <input type="text" id="changeDormitory" name="changeDormitory" class="form-control" placeholder="密码">
                  </div>
                  <div class="form-group">
                    <label for="changePhone">电话</label>
                    <input type="text" id="changePhone" name="email" class="form-control" placeholder="电话">
                  </div>
                  <div class="form-group">
                    <label for="changePassword">密码</label>
                    <input type="password" id="changePassword" name="password" class="form-control" placeholder="密码">
                  </div>
                </div>
                <!-- /.card-body -->
                <div class="card-footer">
                  <button type="button" id="changeButton" class="btn btn-primary">提交</button>
                </div>
            </div>
            <!-- /.card -->
            </div>
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- 控制侧边栏内容在这里 -->
    <div class="p-3">
      <h5>标题</h5>
      <p>侧边栏内容</p>
    </div>
  </aside>
  <!-- /.control-sidebar -->

  <!-- Main Footer -->
  <footer class="main-footer">
    <!-- To the right -->
    <div class="float-right d-none d-sm-inline">
      任何你想要的
    </div>
    <!-- Default to the left -->
    <strong>Copyright &copy; 2021 <a href="#">SuperScope.com</a>.</strong> 保留所有权利。
  </footer>
</div>
<!-- ./wrapper -->

<div class="modal fade" id="modal-danger">
        <div class="modal-dialog">
          <div class="modal-content bg-danger">
            <div class="modal-header">
              <h4 class="modal-title">你确定要这样做吗</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <p>该操作不可返回</p>
            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-outline-light" data-dismiss="modal">关闭</button>
              <button type="button" class="btn btn-outline-light" id="deleteUserid">确认</button>
            </div>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
      </div>
      <!-- /.modal -->



<!-- jQuery -->
<script src="../../static/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../static/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="../../static/dist/js/adminlte.min.js"></script>
<script src="../../static/plugins/toastr/toastr.min.js"></script>
<script type = "text/javascript" >
    $(function (){
        $.ajax({
            url: '/getSession',
            type: 'POST',
            data: {},
            dataType: 'json',
            success: function (data) {
                document.getElementById("username").innerText = data['username'];
                if(data['admin'] === 1){
                    document.getElementById("HelloUser").innerText = "你好! 管理员 " + data['username'];
                    document.getElementById("profileimg").setAttribute("src","../../static/dist/img/管理员.png");
                    document.getElementById("isadmin").innerText = "管理员";
                }
                else{
                    document.getElementById("HelloUser").innerText = "你好! 学生 " + data['username'];
                    document.getElementById("adminMaintenance").hidden = true;
                    document.getElementById("profileimg").setAttribute("src","../../static/dist/img/用户(1).png");
                    document.getElementById("isadmin").innerText = "学生";
                }
                document.getElementById("userid").innerText = data['userid'];
                document.getElementById("dormitory").innerText = data['dormitoryId'];
                document.getElementById("phone").innerText = data['phone_number'];

                document.getElementById("changeDormitory").setAttribute("value",data['dormitoryId']);
                document.getElementById("changePhone").setAttribute("value",data['phone_number']);
            }
        })
    });
</script>

<script type = "text/javascript" >
    $('#deleteUserid').on('click',
  function() {
        var userid = document.getElementById("userid").innerText;
        var action = "delete";

        var data = {
            data:JSON.stringify({
                'userid':userid,
                'action':action
            }),
        }

        //提交
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"/monitor/personalInformation",
            data: data,
            success :function (result){
                toastr.success("注销成功 3s后返回登录页面");
                setTimeout(function (){window.location.href = '/login/login'},3000)
            },
            error:function (result){
                toastr.error("未知错误");
            }
        });
  })
</script>
<script type="text/javascript">
$('#changeButton').on('click',
  function() {
        var userid = document.getElementById("userid").innerText;
        var changeDormitory = $('#changeDormitory').val();
        var changePhone = $('#changePhone').val();
        var changePassword = $('#changePassword').val();
        var action = "change";

        var data = {
            data:JSON.stringify({
                'userid':userid,
                'changeDormitory':changeDormitory,
                'changePhone':changePhone,
                'changePassword':changePassword,
                'action':action
            }),
        }

        if(changeDormitory === "" || changePhone === "" || changePassword === ""){
            toastr.error('不能有数据为空');
            return ;
        }

        if(changePhone.length !== 11){
            toastr.error('请输入正确的电话号码');
            return ;
        }



        //提交
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"/monitor/personalInformation",
            data: data,
            success :function (result){
                if(result === "更新成功"){
                    toastr.success("更新成功");
                    setTimeout(function (){window.location.reload();},1000);
                }
                else
                    toastr.error("更新失败，请检查数据是否正确");
            },
            error:function (result){
                toastr.error("未知错误");
            }
        });
  })
</script>


</body>
</html>
